#include <gtest/gtest.h>
#include "../stdlib/qsort.h"

int intcmp(const void *i, const void *j) {
  return (*(int *)i - *(int *)j);
}

int pstrcmp(const void *i, const void *j) {
  return strcmp(*(char **)i, *(char **)j);
}
#define N 100

TEST(QSORTTEST, FUNCTEST) {

  char* a[] = {"bb" , "aa", "cc"};
  zqsort(a, sizeof(a)/sizeof(char *), sizeof(char *), pstrcmp);
  EXPECT_STREQ("bb", a[1]);

}

TEST(QSORTTEST, QSORT) {
//  int a[] = {2, 1, 4, 4, 5, 7, 20, 30, 3, 33, 23};
  int a[N];
  for (int i = 0; i < N; i++) {
    a[i] = rand() % 1000;
  }
  zqsort(a, sizeof(a)/sizeof(int), sizeof(int), intcmp);
  EXPECT_LT(a[0], a[1]);
  EXPECT_LT(a[1], a[2]);
  EXPECT_LT(a[2], a[3]);
  EXPECT_LT(a[4], a[5]);
  EXPECT_LT(a[N-2], a[N-1]);
}
